package com.ril.financial.parsers;

import com.ril.financial.model.BankStatement;
import com.ril.financial.model.Transaction;
import com.ril.financial.model.TransactionCollection;

public abstract class BaseFileParser implements Parser {
    private final String _filename;

    private boolean _alreadyParsed;
    private BankStatement _statement;

    public BaseFileParser(String filename) {
        _filename = filename;
        _alreadyParsed = false;
    }

    public void setAlreadyParsed(boolean alreadyParsed) {
        _alreadyParsed = alreadyParsed;
    }

    public boolean alreadyParsed() {
        return _alreadyParsed;
    }

    public String getFilename() {
        return _filename;
    }

    public TransactionCollection<Transaction> getTransactions() {
        if (!alreadyParsed()) {
            parse();
        }
        return getStatement().getTransactions();
    }

    public BankStatement getStatement() {
        if (!alreadyParsed()) {
            parse();
        }

        return _statement;
    }

    public void setStatement(BankStatement statement) {
        _statement = statement;
    }
}
